<template>
  <div class="content">
    <!-- 订单信息 -->
    <!-- 订单信息 -->
    <div style="width: 100%;background-color: ;position: relative;top: 0;left: 0;">
      <headers index="2"></headers>
    </div>
    <div style="min-height:80vh ; padding: 2vh 10vw ; box-sizing: border-box;">
      <el-form v-if="choose_index==1" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px" class="demo-ruleForm">
            <el-form-item :label="$t('Logistics_options')" prop="logistics">
               <el-radio-group @change="type_of_shipping" v-model="ruleForm.logistics">
                 <!-- 海运cj -->
                 <el-radio :label="1">{{$t('sea_transportation_cj')}}</el-radio>
                 <!-- 航空cj -->
                 <el-radio :label="2">{{$t('aviation_cj')}}</el-radio>
                 <!-- 无验收无开封(海运) -->
                 <el-radio :label="3">{{$t('No_acceptance')}}</el-radio>
                 <!-- 海运CBM(LCL) -->
                 <el-radio :label="4">{{$t('sea_transportation_cmb')}}</el-radio>
                 <!-- 食品/电器(无需个人通关码/普通海关) -->
                 <el-radio :label="5">{{$t('food')}}</el-radio>
               </el-radio-group>
            </el-form-item>
            <!-- 通关方式 -->
            <el-form-item :label="$t('Customs_clearance_method')" prop="clearance">
               <el-radio-group v-model="ruleForm.clearance" @change="type_of_shipping">
                 <!-- 个人通关 -->
                 <el-radio :label="1">{{$t('Personal_clearance')}}</el-radio>
                 <!-- 企业通关 -->
                 <el-radio :label="2">{{$t('Enterprise_clearance')}}</el-radio>
               </el-radio-group>
            </el-form-item>
            <!-- 收货人姓名 -->
            <el-form-item v-if="ruleForm.clearance==1" :label="$t('Consignee_Name')" prop="name">
              <div>
                <el-input class="input_class" v-model="ruleForm.name" :placeholder="$t('name_h')"></el-input>
              </div>
              <div>
                <el-input class="input_class" v-model="ruleForm.en_name" :placeholder="$t('name_e')"></el-input>
              </div>
            </el-form-item>
            <el-form-item v-if="ruleForm.clearance==2" label="企业名" prop="company_name">
              <div>
                <el-input class="input_class" v-model="ruleForm.company_name" placeholder="企业名(韩文)"></el-input>
              </div>
              <div>
                <el-input class="input_class" v-model="ruleForm.en_company_name" placeholder="企业名(英文)"></el-input>
              </div>
            </el-form-item>
            <!-- 通关编码方式 -->
            <el-form-item :label="$t('Clearance_code_method')" prop="directory">
               <el-radio-group v-model="ruleForm.directory" >
                 <!-- 个人目录通关(空运) -->
                 <el-radio v-if="ruleForm.clearance==1 && ruleForm.logistics!=5" :label="1">{{$t('Personal_directory_customs_clearance_air_freight')}}</el-radio>
                 <!-- 个人简易通关(空运) -->
                 <el-radio v-if="ruleForm.clearance==1 && ruleForm.logistics!=5" :label="2">{{$t('Personal_simple_customs_clearance_air_freight')}}</el-radio>
                 <!-- 企业目录通关(空运) -->
                 <el-radio v-if="ruleForm.clearance==2 && ruleForm.logistics!=5" :label="3">{{$t('Enterprise_directory_customs_clearance_air_freight')}}</el-radio>
                 <!-- 企业简易通关(空运) -->
                 <el-radio v-if="ruleForm.clearance==2 && ruleForm.logistics!=5" :label="4">{{$t('Easy_customs_clearance_air_freight')}}</el-radio>
                 <!-- 目录通关(海运) -->
                 <el-radio  :label="5">{{$t('Catalog_clearance_sea_freight')}}</el-radio>
                 <!-- 简易通关(海运) -->
                 <el-radio :label="6">{{$t('Easy_customs_clearance_sea_freight')}}</el-radio>
               </el-radio-group>
            </el-form-item>
            <!-- 通关码校验 -->
            <el-form-item v-if="ruleForm.clearance==1" :label="$t('Clearance_code_check')" prop="clearance_code">
              <el-input class="input_class" v-model="ruleForm.clearance_code" :placeholder="$t('Clearance_code_check')"></el-input>
              <!-- <el-button type="primary" :loading="checkCodeLoading" @click="checkCode(ruleForm.clearance_code)" style="margin-left: 20px;">{{$t('checkout')}}</el-button> -->
            </el-form-item>
            <el-form-item  v-if="ruleForm.clearance==2" :label="$t('Business_license_upload')" prop="license">
              <el-upload
               action=""
                class="upload-demo"
                :before-upload="fileChange"
                :show-file-list="false"
                list-type="picture">
                <!-- 点击上传 -->
                <el-button :loading='upLoading' size="small" type="primary">{{$t('Click_to_upload')}}</el-button>
                <!-- 只能上传jpg/png/pdf文件 -->
                <div slot="tip" class="el-upload__tip">{{$t('Upload_files_only')}}</div>
              </el-upload>
              <img v-if="ruleForm.license && ruleForm.file.type != 'application/pdf'"  :src="imgUrl+ruleForm.license" width="100px" alt="" />

              <el-button v-if="ruleForm.license && ruleForm.file.type =='application/pdf'"  size="small" type="text">
                <!--pdf文件 点击查看 -->
                {{$t('pdf_file')}}  <a :href="imgUrl+ruleForm.license" target="_blank">{{$t('click_to_view')}}</a>

                </el-button>
            </el-form-item>
            <!-- 手机号 -->
            <el-form-item :label="$t('cell_phone_number')" prop="mobile">
              <el-input  type="text" maxlength="11" @input="(e)=>{ruleForm.mobile = e.replace(/[^0-9]/g,'')}"  class="input_class" v-model="ruleForm.mobile" :placeholder="$t('cell_phone_number')"></el-input>
            </el-form-item>
            <!-- 地址 -->
            <el-form-item :label="$t('site')" prop="address">
              <el-input class="input_class" v-model="ruleForm.address" :placeholder="$t('site')"></el-input>
            </el-form-item>
            <!-- 详细地址 -->
            <el-form-item :label="$t('detailed_address')" prop="address2">
              <el-input class="input_class" v-model="ruleForm.address2" :placeholder="$t('detailed_address')"></el-input>
            </el-form-item>
            <!-- 邮政编码 -->
            <el-form-item :label="$t('postal_code')" prop="zip_code">
              <el-input class="input_class" v-model="ruleForm.zip_code"  :placeholder="$t('postal_code')"></el-input>
              <el-button type="primary" style="margin-left: 20px;"> <a href="https://www.naver.com" style="color: #fff;" target="_blank" >{{$t('Zip_code_search')}}</a> </el-button>
            </el-form-item>
            <el-form-item :label="$t('Delivery_requirement')" prop="ask">
              <el-input class="input_class" v-model="ruleForm.ask" :placeholder="$t('Delivery_requirement')"></el-input>
            </el-form-item>
            <div style="width: 100%;display: flex;justify-content: flex-end;">
              <el-button type="primary" :loading="btn1" @click="next('ruleForm' , 1)"  style="margin-left: 20px;">{{$t('next')}}</el-button>
            </div>

          </el-form>
          <!-- 物品信息 -->

      <!-- $t('') -->
          <el-form v-if="choose_index==2" :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-width="200px" class="demo-ruleForm">
              <!-- 快递单号 -->
              <el-form-item :label="$t('tracking_numbe')" prop="tracking_number">
                <el-input class="input_class" v-model="ruleForm2.tracking_number" :placeholder="$t('tracking_numbe')"></el-input>
              </el-form-item>
              <!-- 国内快递公司 -->
              <el-form-item :label="$t('Domestic_express_company') " prop="express_company">
                <el-input class="input_class" v-model="ruleForm2.express_company" :placeholder="$t('Domestic_express_company')"></el-input>
              </el-form-item>
              <!-- 国内运费 -->
              <el-form-item :label="$t('home_freight')" prop="domestic_freight">
                <el-input class="input_class" v-model="ruleForm2.domestic_freight" :placeholder="$t('home_freight')"></el-input>
              </el-form-item>
              <!-- 商品名称 -->
              <el-form-item :label="$t('product_name')" prop="name">
                <el-input class="input_class" v-model="ruleForm2.name" :placeholder="$t('product_name')"></el-input>
              </el-form-item>
            <!-- 商品分类-->
              <el-form-item :label="$t('goods_category')" prop="cid">
                 <!-- <el-select class="input_class" v-model="ruleForm2.cid" :placeholder="$t('goods_category')">
                    <el-option
                      v-for="item in shopClassList"
                      :key="item.id"
                      :label="item.title"
                      :value="item.id">
                    </el-option>
                  </el-select> -->
                  <el-select
                     v-model="ruleForm2.cid"
                     :multiple='false'
                     filterable
                     remote
                     reserve-keyword
                     :placeholder="$t('goods_category')"
                     :remote-method="remoteMethod"
                     :loading="selectLoading">
                     <el-option
                       v-for="item in shopClassList"
                       :key="item.id"
                       :label="item.title"
                       :value="item.id">
                     </el-option>
                   </el-select>
              </el-form-item>
              <!-- 产品图片 -->
              <el-form-item :label="$t('product_picture')" prop="pic">
                  <el-upload
                   :http-request="upload"
                   action="#"
                   :disabled="ruleForm2.picList.length>0"
                   :limit="1"
                   :file-list="ruleForm2.picList"
                   list-type="picture-card"
                   :before-upload="picChange"
                   >
                   <i class="el-icon-plus"></i>
                    <div slot="file" slot-scope="{file}">
                         <img
                           class="el-upload-list__item-thumbnail"
                           :src="file.url" alt=""
                         >
                         <span class="el-upload-list__item-actions">
                           <span
                             class="el-upload-list__item-delete"
                             @click="handleRemove(file)"
                           >
                             <i class="el-icon-delete"></i>
                           </span>
                         </span>
                       </div>
                 </el-upload>

              </el-form-item>
              <!-- 订单号码 -->
              <el-form-item :label="$t('order_number')" prop="order_no">
                <el-input class="input_class" v-model="ruleForm2.order_no" :placeholder="$t('order_number')"></el-input>
              </el-form-item>
              <!-- 商品价格 -->
              <el-form-item :label="$t('commodity_prices')" prop="price">
                <el-input class="input_class" v-model="ruleForm2.price" :placeholder="$t('commodity_prices')"></el-input>
                <el-button type="text" style="margin-left: 20px; color: red;">{{$t('extra_charge')}}</el-button>

              </el-form-item>
              <!-- 商品颜色 -->
              <el-form-item :label="$t('product_color')" prop="colour">
                <el-input class="input_class" v-model="ruleForm2.colour" :placeholder="$t('product_color')"></el-input>
              </el-form-item>
              <!-- 商品尺码 -->
              <el-form-item :label="$t('Product_Size')" prop="size">
                <el-input class="input_class" v-model="ruleForm2.size" :placeholder="$t('Product_Size')"></el-input>
              </el-form-item>
              <!-- 商品数量 -->
              <el-form-item :label="$t('BNUM')" prop="num">
                <el-input class="input_class" v-model="ruleForm2.num" :placeholder="$t('BNUM')"></el-input>
              </el-form-item>
              <!-- 商品链接 -->
              <el-form-item :label="$t('ProductUrl')" prop="link">
                <el-input class="input_class" v-model="ruleForm2.link" :placeholder="$t('ProductUrl')"></el-input>
              </el-form-item>
              <!-- 备注 -->
              <el-form-item :label="$t('remark')" prop="ask">
                <el-input class="input_class" type="textarea" v-model="ruleForm2.ask" :placeholder="$t('remark')"></el-input>
              </el-form-item>
              <!-- 韩国信息 -->
              <div style="width: 200px; text-align: right;font-size: 20px;">
                <!-- 韩国信息填写 -->
                {{$t('Korean_information_filling')}}
              </div>
              <!-- 商品编码 -->
              <el-form-item :label="$t('commodity_code')" prop="kor_code">
                <el-input class="input_class"  v-model="ruleForm2.kor_code" :placeholder="$t('commodity_code')"></el-input>
              </el-form-item>
              <!-- 订单号 -->
              <el-form-item :label="$t('order_number')" prop="kor_order_code">
                <el-input class="input_class"  v-model="ruleForm2.kor_order_code" :placeholder="$t('order_number')"></el-input>
              </el-form-item>
              <!-- 卖家管理编号 -->
              <el-form-item :label="$t('Seller_management_number')" prop="kor_seller">
                <el-input class="input_class"  v-model="ruleForm2.kor_seller" :placeholder="$t('Seller_management_number')"></el-input>
              </el-form-item>
              <!-- 渠道 -->
              <el-form-item :label="$t('channel')" prop="kor_channel_id">
                <el-select class="input_class" v-model="ruleForm2.kor_channel_id" :placeholder="$t('channel')">

                   <el-option
                     v-for="item in channelList"
                     :key="item.id"
                     :label="lang==1?item.name:item.kor_name"
                     :value="item.id">
                   </el-option>
                 </el-select>
              </el-form-item>
              <div style="width: 100%;display: flex;justify-content: flex-end;">
                <el-button type="primary" @click=" back() " :loading="backLoading" style="margin-left: 20px;">上一步</el-button>
                <el-button type="primary" @click="submitForm2('ruleForm2' , 2)" :loading="btn2" style="margin-left: 20px;">{{$t('next')}}</el-button>
              </div>


          </el-form>

        <!-- 物品信息 -->
          <el-form v-if="choose_index==3"  label-width="200px" class="demo-ruleForm">
            <el-checkbox-group v-model="checkList">
              <!-- 附加服务 -->
              <el-descriptions class="margin-top" :title="$t('accessorial_service')" :column="1" border>
                  <!-- <template slot="extra">
                    <el-button type="primary" size="small">操作</el-button>
                  </template> -->

                    <el-descriptions-item v-for="(item,index) in additionalList" :key="index" :label="item.name">

                      <el-checkbox v-for="(val , key) in item.aa" :key="key" :label="val.id">{{val.name}}</el-checkbox>
                    </el-descriptions-item>

                </el-descriptions>
            </el-checkbox-group>
            <div style="width: 100%;display: flex;justify-content: flex-end;">
              <!-- 上一步 -->
              <el-button type="primary" @click=" back() " style="margin-left: 20px;" :loading="backLoading">{{$t('last_step')}}</el-button>
              <el-button type="primary" @click="submitForm3('' , 3)" :loading="btn3" style="margin-left: 20px;">{{$t('submit')}}</el-button>
            </div>

          </el-form>
    </div>

  </div>
</template>

<script>
import navBer from "@/components/nav_ber"
import headers from "@/components/header"
 import {
   agreement_detail,
   comment_detail,
   order_add,
   index_cate,
   index_channel,
   goods_add,
   additional_index,
   order_additional_add,
   order_detail,
   checkCode
 } from '@/utils/wqzApi'
import exoprt_file from '@/utils/expor_file' // 导出excel文件
export default {
    components:{
      navBer,
      headers
    },
    data () {
        return {
          selectLoading:false,
          upLoading:false,
          lang:localStorage.getItem("lang")=='zh-CN'?1:2,
          checkCodeLoading:false,
          imgUrl:process.env.VUE_APP_BASE_imgUrl,
          backLoading:false,
          btn1:false,
          btn2:false,
          btn3:false,
          dialogVisible: false, //商品图显示隐藏
          choose_index:1  ,
          shopClassList:[
            {label:'分类1' , value:0},
            {label:'分类1' , value:1},
            {label:'分类1' , value:2},
          ],//商品分类列表
          additionalList:[],//附加费列表
          checkList:[],//附加费选中项
          channelList:[],//渠道列表
          rules:{
            logistics: [
              { required: true, message:this.$t('public.Please_select'), trigger: 'blur' },
            ],
            clearance:[
              { required: true, message:this.$t('public.Please_select'), trigger: 'blur' },
            ],
            directory:[
              { required: true, message:this.$t('public.Please_select'), trigger: 'blur' },
            ],
            name: [
               {required: true, validator: (rule, value, callback)=>{
                 if (this.ruleForm.name === '') {
                   callback(new Error(this.$t('public.Please_enter_your_name_h')));
                   return
                 }
                 if (this.ruleForm.en_name === '') {
                   callback(new Error(this.$t('public.Please_enter_your_name_e')));
                   return
                 }
                callback();
               }, trigger: 'blur' }
            ],
            company_name:[
               {required: true, validator: (rule, value, callback)=>{
                 if (this.ruleForm.company_name === '') {
                   callback(new Error(this.$t('public.Please_enter_your_company_name_h')));
                   return
                 }
                 if (this.ruleForm.en_company_name === '') {
                   callback(new Error(this.$t('public.Please_enter_your_company_name_e')));
                   return
                 }
                callback();
               }, trigger: 'blur' }
            ],
            license:[
               {required: true, validator: (rule, value, callback)=>{
                 if (this.ruleForm.license === '') {
                   callback(new Error(this.$t('public.Please_upload_your_business_license')));
                   return
                 }
                callback();
               }, trigger: 'blur' }
            ],
            clearance_code:[
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            zip_code:[
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            mobile:[
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            address:[
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            address2:[
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
          },
          rules2:{
            domestic_freight:[
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            order_code: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            order_no: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            express_company: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            name: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            cid: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            price: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            pic: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            colour: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            size: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            num: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            link: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            kor_code: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            kor_seller:[
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            kor_order_code: [
              { required: true, message:this.$t('public.Please_enter'), trigger: 'blur' },
            ],
            kor_channel_id: [
              { required: true, message:this.$t('public.Please_select'), trigger: 'blur' },
            ],
          },
          code:'',//订单code
          goodsID:'',//商品ID
          ruleForm2:{ //物品信息
            "type": 1, //1代发 2代发代买
            "order_code": "", //订单code
            "express_company": "", //国内快递公司
            "domestic_freight": "", //国内运费
            "tracking_number": "", //快递单号
            "order_no": "", //订单号码
            "colour": "", //颜色
            "size": "", //尺码
            "num": "", //数量
            "ask": "", //要求（备注）
            "price": "", //人民币价格超过150美金提示有税收
            "name": "", //产品名
            "cid": "", //分类id
            "link": "", //商品链接
            "website": "", //代替网站链接
            "pic": "", //商品图片链接
            'picList':[],
            "kor_code": "", //韩国信息-商品编码
            "kor_order_code": "", //韩国信息-订单编号
            "kor_seller": "", //韩国信息-卖家管理编号
            "kor_channel_id": null //渠道id
          },
          ruleForm:{
           "type": 1, //1代发 2代发代买
           "name": "", //收件人
           "company_name": "", //企业名（2选1，选企业走企业名，选个人走个人名）
           "logistics": 1, //1海运 2航空 3无验收，无开封 4海运CBM 5食品EMS
           "clearance": 1, //1个人通关 2海运通关
           "clearance_code": "", //通关编码
           "license": "", //营业执照图
           "mobile": "", //手机号
           "address": "", //地址
           "address2": "", //详细地址
           "zip_code": "", //邮编
           "ask": "", //送货要求
           "en_name": "", //英文收件人名
           "en_company_name": "", //英文企业收件人名
           "directory": null ,//目录空运(个人目录是1/个人简易是3/企业目录是2/企业简易是3),海运(目录通关：1 /简易通关：3)
           'file':null,
          },
          order_id:null,
          isEdit:false,
        }

    },
    mounted() {
      this.getcate()
      this.additional_index()
      var params = this.$getUrlParams()
      if(params.id){
        this.order_id = this.$getUrlParams().id
        this.isEdit = true
        var data = {
          id:this.order_id,
          type:1
        }
        this.order_detail(data , 1)
      }else{
        // 不是查看详情
        this.isEdit=false
        // console.log('不是查看详情')
      }
    },
    methods:{
      // 商品分类搜索
      remoteMethod(query) {
        console.log(query)
        // 获取商品分类列表
        this.selectLoading = true
        index_cate({name:query}).then(res=>{
          this.selectLoading = false
          var lang = localStorage.getItem('lang')
          if(lang== 'zh-CN'){
            res.data.forEach((item,index)=>{
              res.data[index].title = item.name
            })
          }
          if(lang== 'ko'){
            res.data.forEach((item,index)=>{
              res.data[index].title = item.kor_name
            })

          }
          this.shopClassList = res.data
        }).catch(err=>{
          this.selectLoading = false
        })
      },
      type_of_shipping(e){
        this.ruleForm.directory = null
        // 物流选想为食品/电器 的时候不能空运 重置通关码方式
      },
      checkCode(code){
        // 通关码教案
        if(!code){
          this.$message({
            type:'error',
            message:this.$t('Please_enter_the_clearance_code')
          })
          return
        }
        this.checkCodeLoading = true
        var data = {
          clearance_code:code
        }
        checkCode(data).then(res=>{
          // console.log(res , '校验结果')
          this.$message({
            type:'success',
            message:this.$t('The_clearance_code_is_verified_successfully')
          })
          this.checkCodeLoading = false
        }).catch(err=>{
          // console.log(err , '校验失败结果')
          this.checkCodeLoading = false
        })


      },
      back(){
        this.backLoading = true
        if(this.choose_index == 3){
          var data = {
            id:this.goodsID,
            type:2
          }
          this.order_detail(data , 2)
          return
        }
        if(this.choose_index == 2){
          // this.choose_index = 1
          var data = {
            id:this.code,
            type:1
          }
          this.order_detail(data , 1)
          return
        }
      },
      order_detail(data , index){
        // 订单商品修改的时候的详情

        order_detail(data).then(res=>{
          this.backLoading = false
          if(index == 3){
            this.checkList = []
            res.data.forEach((item,index)=>{
              this.checkList.push(item.aid)
            })
          }
          if(index == 2){
            this.ruleForm2 = res.data
            this.ruleForm2.picList = [{url:this.imgUrl+res.data.pic}]
            this.choose_index = index
          }
          if(index == 1){
            // console.log(res.data , '图片信息')
            this.ruleForm = res.data
            if(res.data.license.indexOf("pdf")>0){
              this.ruleForm.file = {
                type:"application/pdf"
              }
            }else{
              // console.log('这个是图片')
                this.ruleForm.file = {
                  type:"img"
                }
            }

            this.choose_index = index
          }


        })
      },
      additional_index(){
        //附加费列表
        additional_index({}).then(res=>{
          this.additionalList = res.data
        })
      },

      submitForm2(ref  , index){
        var data = JSON.parse(JSON.stringify(this.ruleForm2))
          data.order_code = this.code

        this.$refs[ref].validate((valid) => {
          if (valid) {
            this.btn2 = true
            this.submit2(data)
            var params = {
              id:this.code,
              type:3
            }
            if(this.isEdit){
              params.id = this.order_id
            }
            this.order_detail(params , 3)
          } else {
            console.log('error submit!!');
            this.btn2 = false
            return false;
          }
        });
      },
      submit2(data){
        goods_add(data).then(res=>{
          // this.$message({
          //   type:'success',
          //   message:this.$t('public.Operation_successful')
          // })
          this.btn2 = false
          this.goodsID = res.data
          this.choose_index = 3

        }).catch(err=>{
          this.btn2 = false
        })
      },
      // 提交附加费
      submitForm3(){
        var aid = this.checkList.join(',')
        var data = {
          "type": 1, //1代发 2代发代买
          "aid": aid, //附加费id
          "order_code": this.code, //订单code
          "order_goods_id": this.goodsID //订单商品id
        }
        order_additional_add(data).then(res=>{
          this.$message({
            type:'success',
            message:this.$t('public.Operation_successful')
          })
          localStorage.setItem('chooseHeadrIndex' , 3)
                    this.$router.push({ path: '/Inventory_management'})
                    setTimeout(()=>{
                      location.reload()
                    },20)

        })
          // order_additional_add()
      },
      picChange(file){
        if(file.type == 'image/png' ||  file.type == 'image/jpeg' ||  file.type == 'image/jpg'){

        }else{
          this.$message({
            type:'error',
            message:this.$t('public.Upload_format_mismatch')
          })
          return false
        }
      },
      upload(file ){
        file = file.file
         this.ruleForm.file = file
         let data = new FormData()
         data.append('file', file)
         exoprt_file('index.php/index/index/file'  , data).then(res=>{
           this.ruleForm2.pic= res
           this.ruleForm2.picList = [{url:process.env.VUE_APP_BASE_imgUrl+this.ruleForm2.pic}]
        })
      },
      handleRemove(){
        this.ruleForm2.picList = []
        this.$forceUpdate()
      },
      getcate(){
        // 获取商品分类列表
        index_cate({}).then(res=>{
          var lang = localStorage.getItem('lang')
          if(lang== 'zh-CN'){
            res.data.forEach((item,index)=>{
              res.data[index].title = item.name
            })
          }
          if(lang== 'ko'){
            res.data.forEach((item,index)=>{
              res.data[index].title = item.kor_name
            })

          }
          this.shopClassList = res.data
        })
        // 获取渠道列表
        index_channel({}).then(res=>{

            this.channelList = res.data
        })
      },
      fileChange(file) {
        if(file.type == 'image/png' || file.type == 'application/pdf' || file.type == 'image/jpeg' ||  file.type == 'image/jpg'){
           this.ruleForm.file = file
           let data = new FormData()
           data.append('file', file)
           this.upLoading = true
           exoprt_file('index.php/index/index/file'  , data).then(res=>{
             this.ruleForm.license = res
             this.upLoading = false
          }).catch(err=>{
            this.upLoading = false
          })
        }else{
          this.$message({
            type:'error',
            message:this.$t('public.Upload_format_mismatch')
          })
        }
        return
      },
      next(ref , index){
        this.btn1 = true
        this.$refs[ref].validate((valid) => {
          if (valid) {
           this.submit_one(index)

          } else {
            console.log('error submit!!');
            this.btn1 = false
            return false;
          }
        });
      },
      submit_one(){
        var data = JSON.parse(JSON.stringify(this.ruleForm))
        delete data.file
        order_add(data).then(res=>{
          this.choose_index = 2
          this.code = res.data
          var data = {
            id:this.order_id,
            type:2
          }
          if(this.isEdit){
            this.order_detail(data , 2)
          }
          this.btn1 = false
        }).catch(err=>{
          console.log(err , '错误信息')
          this.btn1 = false
        })
      }

    }
}
</script>


<style lang="scss" scoped>
  .input_class{
    // width: 10;
    margin-bottom: 5px;
  }
  .content{
    width: 100%;

  }
</style>

